package itheima.zuoye.Test8;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
//键盘输入多个学生信息包括姓名和年龄，学生信息之间用逗号隔开，键盘输入 ok 结束录入
//将录入的信息保存到指定路径文件中
public class test {
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        String filePath = "D:\\javabasepro\\java AdvanceProject\\day10\\src\\itheima\\zuoye\\Test8\\1.txt";
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath))) {
        int count = 0;
        while (true) {
            count++;
            System.out.println("请输入第"+ (count) +"个学生姓名和年龄，学生信息之间用逗号隔开（ok表示结束）：");
            String line = scanner.nextLine();
            if ("ok".equals(line)) {
                System.out.println("拜拜!");
                break;
            }
            writer.write(line);
            writer.newLine(); // 换行

        }

    }catch (IOException e){
            e.printStackTrace();
        }finally {
            scanner.close();
        }




        }

        }


